package net.root.plain.alarm;

import java.util.ArrayList;
import net.root.plain.main.R;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressWarnings("rawtypes")
public class AlarmListAdapter extends ArrayAdapter {
	private Context mContext;
	private int mResource;
	private ArrayList<AlarmDTO> mList;
	private LayoutInflater mInflater;

	@SuppressWarnings("unchecked")
	public AlarmListAdapter(Context context, int layoutResource,
			ArrayList<AlarmDTO> objects) {
		// TODO Auto-generated constructor stub
		super(context, layoutResource, objects);
		this.mContext = context;
		this.mResource = layoutResource;
		this.mList = objects;
		this.mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		AlarmDTO dto = mList.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(mResource, null);
		}

		if (dto != null) {
			ImageView ivThumbnail = (ImageView) convertView
					.findViewById(R.id.list_view_list_row_thumbnail);
			TextView ltv = (TextView) convertView
					.findViewById(R.id.list_view_list_row_large_text);
			TextView stv = (TextView) convertView
					.findViewById(R.id.list_view_list_row_normal_text);
			
			if (dto.getAlarmStatus()==0) {
				ivThumbnail.setBackgroundColor(Color.RED);
			}else{
				ivThumbnail.setBackgroundColor(Color.GREEN);
			}
			// 스크린네임 세팅
			ltv.setText(dto.getAlarmLabel());
			// 텍스트 세팅
			stv.setText(TimeUtil.convertString(Long.parseLong(dto.getAlarmTime())));
		}

		return convertView;
	}
}
